package com.soft.cake.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.soft.cake.mapper.UserMapper;
import com.soft.cake.pojo.Order;
import com.soft.cake.pojo.User;
import com.soft.cake.service.IUserService;
@Service
public class UserServiceImpl implements IUserService {
	
	@Autowired
	private UserMapper userMapper;
	
	/**
	 * @author Guo Xue
	 * @description 根据用户id查找用户
	 * @param userId
	 * @param User
	 */
	@Override
	public User selectByPrimaryKey(Integer userId) {
		User user = userMapper.selectByPrimaryKey(userId);
		return user;
	}
	
	/**
	 * @author Guo Xue
	 * @description 根据主键修改用户
	 * @param record
	 * @param boolean
	 */
	@Override
	public boolean updateByPrimaryKeySelective(User record) {
		// TODO Auto-generated method stub
		userMapper.updateByPrimaryKeySelective(record);
		return false;
	}
	
	@Override
	public void add(User user) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void update(User user) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public User load(int id) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public List<User> getUserAddressList() {
		return userMapper.getAddressList();
	}
	@Override
	public List<User> getUserOrderList() {
		return userMapper.getOrderList();
	}
	/**
	 * 用户注册
	 */
	@Override
	public boolean register(User user) {
		// TODO Auto-generated method stub
		User user2 = userMapper.selectByUsername(user.getUserUsername());
		if(user2==null&&userMapper.insert(user)!=0)
			return true;
		return false;
	}
	/**
	 * 用户登录
	 */
	@Override
	public boolean login(User user) {
		// TODO Auto-generated method stub
		if(userMapper.selectByUser(user)!=null)
			return true;
		return false;
	}
	
	/**
	 * 	结算订单获取用户
	 */
	@Override
	public User settleOrderGetUser(Integer orderId) {
		// TODO Auto-generated method stub
		return userMapper.selectByOrderId(orderId);
	}
	
	
	@Override
	public User getUserWithAddress(Integer orderId) {
		// TODO Auto-generated method stub
		return userMapper.selUserWithAddressByOrderId(orderId);
	}
	
	

}
